<?php

class People_GroupController extends Base_Controller_Action
{
    public function indexAction()
    {
        $village = new Model_Village();
        try {
            #$village->readByUser();
            $village->read($this->_getParam('aid'));
        }
        catch (Base_Exception $e) {
            return $this->_helper->ErrorPage($e->getMessage());
        }
        
        //question list
        $dbTable = new Table_Group();
        $whereArray['`vid` = ?'] = $village->vid;
        $this->view->village = $village;
        $this->view->entries = $dbTable->view($whereArray, 'gid ASC');

    }

    public function manageAction()
    {
        $village = new Model_Village();
        try {
            $village->read($this->_getParam('aid'));
        }
        catch (Base_Exception $e) {
            return $this->_helper->ErrorPage(404);
        }
        
        //question list
        $dbTable = new Table_Group();
        $whereArray['`vid` = ?'] = $village->vid;
        $this->view->village = $village;
        $this->view->street = $village->getStreet();
        $this->view->entries = $dbTable->view($whereArray, 'gid ASC');

    }
    
    public function createAction()
    {
        //create form
        $this->form = new Form_Group_Create();
        
        try {
            $this->create('group');
        }
        catch (Base_Model_Exception $e) {
            return $this->_helper->ErrorPage($e->getMessage());
        }
        
        $village = new Model_Village();
        try {
            $village->readByUser();
        }
        catch (Base_Exception $e) {
            return $this->_helper->ErrorPage($e->getMessage());
        }
        
        //check oid
        $this->form->vid->setValue($village->vid);
    }
    
    public function modifyAction()
    {
        //create form
        $this->form = new Form_Group_Modify();
        
        try {
            $this->modify('group');
        }
        catch (Base_Model_Exception $e) {
            return $this->_helper->ErrorPage($e->getMessage());
        }
    }
    
    public function deleteAction()
    {
        $this->form = new Form_Group_Delete();
        
        //drop post
        try {
            $this->delete('group');
        }
        catch (Base_Model_Exception $e) {
            return $this->_helper->ErrorPage($e->getMessage());
        }
    }
}